package com.weidey.blogWeb.controller;

import com.weidey.blog.service.IArticleService;
import com.weidey.blogWeb.service.ISignService;
import com.weidey.blogWeb.service.IWebArticleService;
import com.weidey.blogWeb.service.IWebUserService;
import com.weidey.common.core.domain.AjaxResult;
import com.weidey.common.core.domain.entity.SysUser;
import com.weidey.common.utils.SecurityUtils;
import com.weidey.system.mapper.SysUserMapper;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import javax.naming.ldap.PagedResultsControl;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;


/**
 * 用户信息Controller
 * @Author: weidey
 */
//@Tag(tags = "用户信息")
@RestController
@RequestMapping("/blog/web/user")
public class WebUserController {

    @Resource
    private SysUserMapper userMapper;

    @Resource
    private ISignService signService;

    @Resource
    private IWebArticleService webArticleService;



    @GetMapping("/select/info")
//    @ApiOperation("根据id获取用户信息")
    public AjaxResult getUserInfoById(@RequestParam("userId") Long id){
        //TODO 根据id获取用户信息
        SysUser blogWebUser =  userMapper.selectUserInfoById(id);
        return AjaxResult.success(blogWebUser);
    }

    @GetMapping("/my/article")
//    @ApiOperation("获取我上传的文章")
    public AjaxResult getMyArticle(){
        //获取用户id
        Long userId = SecurityUtils.getUserId();
        //调用服务获取我的文章
        return webArticleService.getMyArticle(userId);
    }

    @GetMapping("/my/collect")
//    @ApiOperation("获取我的收藏文章")
    public AjaxResult getMyCollectArticle(){
        //获取用户id
        Long userId = SecurityUtils.getUserId();
        return webArticleService.getMyCollectArticle(userId);
    }
    @GetMapping("/my/like")
//    @ApiOperation("获取我的点赞文章")
    public AjaxResult getMyLikeArticle(){
        //获取用户id
        Long userId = SecurityUtils.getUserId();
        return webArticleService.getMyLikeArticle(userId);
    }

//    @ApiOperation("用户签到")
    @GetMapping("/sign")
    public AjaxResult sign(){
        //TODO 用户签到
        // 要求参数 userId  dateStr
        Long userId = SecurityUtils.getUserId();
        //获取当前日期 yyyy-MM-dd
        String dateStr = LocalDate.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
        //TODO  调用签到 服务
        return  signService.doSign(userId,dateStr);
    }

}
